package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.DictionaryDetail;
import cn.wolfcode.crm.service.IDictionaryDetailService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @author konki
 * @time   2018年6月19日 下午7:03:47
 * @email  konki@qq.com
 * @description 
 */
@Controller
@RequestMapping("dictionarydetail")
public class DictionaryDetailController {
	@Autowired
    IDictionaryDetailService service;

	@RequestMapping("")
	@PermissionName("字典明细首页")
	@RequiresPermissions("dictionarydetail:index")
	public String index(){
		return "dictionarydetail/list";
	}
	@RequestMapping("list")
	@PermissionName("字典明细列表")
	@RequiresPermissions("dictionarydetail:list")
	@ResponseBody
	public List<DictionaryDetail> list(Long id){
		return service.selectByDictionaryId(id);
	}

	@RequestMapping("update")
	@PermissionName("字典明细编辑")
	@RequiresPermissions("dictionarydetail:update")
	@ResponseBody
	public JsonResult update(DictionaryDetail dictionarydetail){
		JsonResult jsonResult = new JsonResult();
		try {
			service.updateByPrimaryKey(dictionarydetail);
		}catch (Exception e){
			e.printStackTrace();
			jsonResult.markMsg("编辑字典明细失败");
			return jsonResult;
		}
		return jsonResult;
	}

	@RequestMapping("save")
	@PermissionName("字典明细保存")
	@RequiresPermissions("dictionarydetail:save")
	@ResponseBody
	public JsonResult save(DictionaryDetail dictionarydetail){
		JsonResult jsonResult = new JsonResult();
		try {
			service.insert(dictionarydetail);
		}catch (Exception e){
			e.printStackTrace();
			jsonResult.markMsg("添加字典明细失败");
			return jsonResult;
		}
		return jsonResult;
	}

	@RequestMapping("delete")
	@PermissionName("字典明细删除")
	@RequiresPermissions("dictionarydetail:delete")
	@ResponseBody
	public JsonResult save(Long id){
		JsonResult jsonResult = new JsonResult();
		try {
			service.deleteByPrimaryKey(id);
		}catch (Exception e){
			e.printStackTrace();
			jsonResult.markMsg("删除字典明细失败");
			return jsonResult;
		}
		return jsonResult;
	}
}
